package com.example.springboot.controller;

import com.example.springboot.entity.User;
import com.example.springboot.service.UserRedisService;
import com.example.springboot.service.UserService;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private UserRedisService redisService;

    @GetMapping("/put")
    public Integer put(Integer account){
        User user = new User();
        user.setAccount(account);
        user.setEmail("123@qq.com");
        user.setGender('男');
        user.setName("vison");
        user.setPhone("1321223123");
        user.setType(1);
        user.setHeadimg("123.jpg");
        redisService.put(user);
        return user.getAccount();
    }

    @GetMapping("/cacheable")
    public User cacheable(Integer account){
        User user = new User();
        user.setUid(account);
        return redisService.get(user);
    }

    @GetMapping("/evit")
    public String evit(Integer account){
        userService.deleteUserByUid(account);
        return "ok";
    }

    @GetMapping("/delete")
    public void getString(){
          redisService.delete();
    }
}
